package com.ellecity06.cwhiskymall.ui.contribution

import com.ellecity06.common.base.BaseMviViewModel
import com.ellecity06.common.ktx.postEvent
import com.ellecity06.cwhiskymall.http.request

/**
 * @author ellecity06
 * @time 2024/10/29 15:26
 * @des
 */
class ContributionViewModel :BaseMviViewModel<ContributionState,ContributionIntent>() {
    override suspend fun collectIntent(it: ContributionIntent) {
        when(it){
            is ContributionIntent.FetchData ->{
                fetchUser()
            }

            else -> {}
        }
    }

    private fun fetchUser() {
        request(api = { userAccountInfo() }, success = {
            if (it != null)
                mState.postEvent(ContributionState.AcountInfo(it))
        })
    }
}